home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / misc / tracker.php < prev   
Encoding:
PHP Script  |  2002-06-12  |  6.0 KB  |  211 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Topic Tracker module
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 5th March 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new tracker;
  26.  
  27. class tracker {
  28.  
  29.     var $output    = "";
  30.     var $base_url  = "";
  31.     var $html      = "";
  32.  
  33.     var $forum     = array();
  34.     var $topic     = array();
  35.     var $category  = array();
  36.  
  37.     
  38.     function tracker($is_sub=0) {
  39.     
  40.         //------------------------------------------------------
  41.         // $is_sub is a boolean operator.
  42.         // If set to 1, we don't show the "topic subscribed" page
  43.         // we simply end the subroutine and let the caller finish
  44.         // up for us.
  45.         //------------------------------------------------------
  46.     
  47.         global $ibforums, $DB, $std, $print, $skin_universal;
  48.         
  49.         $ibforums->lang    = $std->load_words($ibforums->lang, 'lang_emails', $ibforums->lang_id);
  50.  
  51.         
  52.         
  53.         //------------------------------------------------------
  54.         // Check the input
  55.         //------------------------------------------------------
  56.         
  57.         $ibforums->input['t'] = $std->is_number($ibforums->input['t']);
  58.         $ibforums->input['f'] = $std->is_number($ibforums->input['f']);
  59.         
  60.         if ($ibforums->input['t'] < 0 or $ibforums->input['f'] < 0)
  61.         {
  62.             if ($is_sub != 1)
  63.             {
  64.                 $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  65.             }
  66.             else
  67.             {
  68.                 return;
  69.             }
  70.         }
  71.         
  72.         //------------------------------------------------------
  73.         // Get the forum info based on the forum ID, get the category name, ID, and get the topic details
  74.         //------------------------------------------------------
  75.         
  76.         $DB->query("SELECT t.tid, f.id as fid, f.read_perms, f.password FROM ibf_topics t, ibf_forums f WHERE t.tid='".$ibforums->input['t']."' AND t.forum_id=f.id");
  77.         
  78.         $this->topic = $DB->fetch_row();
  79.         
  80.        
  81.         
  82.         //------------------------------------------------------
  83.         // Error out if we can not find the forum
  84.         //------------------------------------------------------
  85.         
  86.         if (!$this->topic['fid'])
  87.         {
  88.             if ($is_sub != 1)
  89.             {
  90.                 $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  91.             }
  92.             else
  93.             {
  94.                 return;
  95.             }
  96.         }
  97.         
  98.         //------------------------------------------------------
  99.         // Error out if we can not find the topic
  100.         //------------------------------------------------------
  101.         
  102.         if (!$this->topic['tid'])
  103.         {
  104.             if ($is_sub != 1)
  105.             {
  106.                 $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  107.             }
  108.             else
  109.             {
  110.                 return;
  111.             }
  112.         }
  113.         
  114.         $this->base_url    = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}";
  115.         
  116.         $this->base_url_NS = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}";
  117.         
  118.         //------------------------------------------------------
  119.         // Check viewing permissions, private forums,
  120.         // password forums, etc
  121.         //------------------------------------------------------
  122.         
  123.         if (! $ibforums->member['id'] ) {
  124.             if ($is_sub != 1)
  125.             {
  126.                 $std->Error( array( LEVEL => 1, MSG => 'no_guests') );
  127.             }
  128.             else
  129.             {
  130.                 return;
  131.             }
  132.         }
  133.         
  134.         if ($this->topic['read_perms'] != '*')
  135.         {
  136.             if (! preg_match( "/(^|,)".$ibforums->member['mgroup']."(,|$)/", $this->topic['read_perms'] ) )
  137.             {
  138.                 if ($is_sub != 1)
  139.                 {
  140.                     $std->Error( array( LEVEL => 1, MSG => 'forum_no_access') );
  141.                 }
  142.                 else
  143.                 {
  144.                     return;
  145.                 }
  146.             }
  147.         }
  148.         
  149.         if ($this->topic['password'] != "")
  150.         {
  151.         
  152.             if ( ! $c_pass = $std->my_getcookie('iBForum'.$this->topic['fid']) )
  153.             {
  154.                 $std->Error( array( LEVEL => 1, MSG => 'forum_no_access') );
  155.             }
  156.         
  157.             if ( $c_pass != $this->topic['password'] )
  158.             {
  159.                 $std->Error( array( LEVEL => 1, MSG => 'forum_no_access') );
  160.             }
  161.             
  162.         }
  163.         
  164.         //------------------------------------------------------
  165.         // Have we already subscribed?
  166.         //------------------------------------------------------
  167.         
  168.         $DB->query("SELECT trid from ibf_tracker WHERE topic_id='".$this->topic['tid']."' AND member_id='".$ibforums->member['id']."'");
  169.         
  170.         if ( $DB->get_num_rows() )
  171.         {
  172.             if ($is_sub != 1)
  173.             {
  174.                 $std->Error( array( LEVEL => 1, MSG => 'already_sub') );
  175.             }
  176.             else
  177.             {
  178.                 return;
  179.             }
  180.         }
  181.         
  182.         //------------------------------------------------------
  183.         // Add it to the DB
  184.         //------------------------------------------------------
  185.         
  186.         $db_string = $DB->compile_db_insert_string( array (
  187.                                                              'member_id'   => $ibforums->member['id'],
  188.                                                              'topic_id'    => $this->topic['tid'],
  189.                                                              'start_date'  => time(),
  190.                                                   )       );
  191.                                                   
  192.         $DB->query("INSERT INTO ibf_tracker (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")");
  193.         
  194.         if ($is_sub != 1)
  195.         {
  196.             $print->redirect_screen( $ibforums->lang['sub_added'], "act=ST&f={$this->topic['fid']}&t={$this->topic['tid']}&st={$ibforums->input['st']}" );
  197.         }
  198.         else
  199.         {
  200.             return;
  201.         }
  202.     }
  203. }
  204.  
  205. ?>
  206.  
  207.  
  208.  
  209.  
  210.  
  211.